




#delimit;


set mem 300000;
set mat 700;

set more off;



log using "C:\Old C Drive\F\INTIKAM2009\RESTAT\WEB_Final\RESTATWEB\TABLE4.log",replace;



 use "C:\Old C Drive\F\INTIKAM2009\RESTAT\WEB_Final\RESTATWEB\TABLE7_8data1.dta" ;


/* table 4 column 1  
That is the sample means of individuals without any personal or country variables missing */

#delimit ;
qui reg intikam222 burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab 
 individualism rule_of_law_mean elf85 english french german catholic muslim  
 democratic rgdpch1 kg pop1  _0to25per_new sch25Mean womenMean war752000_noint     
 year1-year11 dedu europe c_europe mediter newasia2 africa lat_amer [pweight=w005] ,robust cluster(count_code) ;
 
  #delimit ;
 preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab 
 individualism rule_of_law_mean elf85 english french german catholic muslim  
 democratic rgdpch1 kg pop1  _0to25per_new sch25Mean womenMean war752000_noint     
 year1-year11 dedu europe c_europe mediter newasia2 africa lat_amer;
 foreach v of varlist _all {;
 ren `v' `v'_m;
 };
 collapse _all;
 save col1_m,replace;
  restore;
  
 #delimit ;
  preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab 
 individualism rule_of_law_mean elf85 english french german catholic muslim  
 democratic rgdpch1 kg pop1  _0to25per_new sch25Mean womenMean war752000_noint     
 year1-year11 dedu europe c_europe mediter newasia2 africa lat_amer;
 collapse (sd) _all;
 foreach v of varlist _all {;
 ren `v' `v'_s;
 replace `v'_s=-1*`v'_s;
 };
 save col1_s,replace;
 restore;
  
  #delimit ;
 preserve;
 use col1_m,clear;
 merge 1:1 _n using col1_s;
 drop _merge;
 aorder;
 xpose, clear varname;
 ren v1 col1;
 save col1,replace;
 restore;

 /* table 4 column 2  - 
That is the sample means of individuals with non-missing personal characteristics.  */
#delimit ;
qui reg intikam222 burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab 
 [pweight=w005] ,robust cluster(count_code) ;

 
   #delimit ;
 preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab ;
 foreach v of varlist _all {;
 ren `v' `v'_m;
 };
 collapse _all;
 save col2_m,replace;
  restore;
  
 #delimit ;
  preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region  citysmall citymiddle
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab ;
 collapse (sd) _all;
 foreach v of varlist _all {;
 ren `v' `v'_s;
 replace `v'_s=-1*`v'_s;
 };
 save col2_s,replace;
 restore;
  
  #delimit ;
 preserve;
 use col2_m,clear;
 merge 1:1 _n using col2_s;
 drop _merge;
 aorder;
 xpose, clear varname;
 ren v1 col2;
 save col2,replace;
 restore;
 
 
 
  /* table 4 column 3  - 
That is the sample means of individuals with non-missing personal characteristics.
city size is not taken into consideration  */
 #delimit ;
 qui reg intikam222 burgtly burgbef protection gun_coll male up50 edu avrburgtly_region 
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab 
 [pweight=w005] ,robust cluster(count_code) ;

 
 
   #delimit ;
 preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region 
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab;
 foreach v of varlist _all {;
 ren `v' `v'_m;
 };
 collapse _all;
 save col3_m,replace;
  restore;
  
 #delimit ;
  preserve;
 keep if e(sample)==1;
 keep burgtly burgbef protection gun_coll male up50 edu avrburgtly_region 
 _20to24age _25to29age _30to34age _35to39age _40to44age _45to49age _50to54age _55to59age _60to64age _65to69age _70plusage 
 single widow livtogether divorced  working lookforjob homekeeper ret_disab;
 collapse (sd) _all;
 foreach v of varlist _all {;
 ren `v' `v'_s;
 replace `v'_s=-1*`v'_s;
 };
 save col3_s,replace;
 restore;
  
  #delimit ;
 preserve;
 use col3_m,clear;
 merge 1:1 _n using col3_s;
 drop _merge;
 aorder;
 xpose, clear varname;
 ren v1 col3;
 save col3,replace;
 restore;
 
 use col1,clear;
 merge 1:1 _varname using col2;
 drop _merge;
merge 1:1 _varname using col3;
 drop _merge;
 aorder;
 
 #delimit cr
 replace _varname="Victim of Burglary This/Last Year" if _varname=="burgtly_m"
replace _varname="Victim of Burglary Before Last Year" if _varname=="burgbef_m"
replace _varname="Gun" if _varname=="gun_coll_m"
replace _varname="Male" if _varname=="male_m"
replace _varname="Upper Income" if _varname=="up50_m"
replace _varname="Education" if _varname=="edu_m"
replace _varname="Burglary rate" if _varname=="avrburgtly_region_m"
replace _varname="Small City" if _varname=="citysmall_m"
replace _varname="Middle Size City" if _varname=="citymiddle_m"
replace _varname="Age20to24" if _varname=="_20to24age_m"
replace _varname="Age25to29" if _varname=="_25to29age_m"
replace _varname="Age30to34" if _varname=="_30to34age_m"
replace _varname="Age35to39" if _varname=="_35to39age_m"
replace _varname="Age40to44" if _varname=="_40to44age_m"
replace _varname="Age45to49" if _varname=="_45to49age_m"
replace _varname="Age50to54" if _varname=="_50to54age_m"
replace _varname="Age55to59" if _varname=="_55to59age_m"
replace _varname="Age60to64" if _varname=="_60to64age_m"
replace _varname="Age65to69" if _varname=="_65to69age_m"
replace _varname="Age70+" if _varname=="_70plusage_m"
replace _varname="Single" if _varname=="single_m"
replace _varname="Widow" if _varname=="widow_m"
replace _varname="Living together" if _varname=="livtogether_m"
replace _varname="Divorced" if _varname=="divorced_m"
replace _varname="Working" if _varname=="working_m"
replace _varname="Looking for job" if _varname=="lookforjob_m"
replace _varname="Home keeper" if _varname=="homekeeper_m"
replace _varname="Retired/disabled" if _varname=="ret_disab_m"
replace _varname="Individualism" if _varname=="individualism_m"
replace _varname="Rule of Law" if _varname=="rule_of_law_mean_m"
replace _varname="Ethnolingu. Fragment" if _varname=="elf85_m"
replace _varname="British Legal Origin" if _varname=="english_m"
replace _varname="French Legal Origin" if _varname=="french_m"
replace _varname="German Legal Origin" if _varname=="german_m"
replace _varname="Percent Catholic" if _varname=="catholic_m"
replace _varname="Percent Muslim" if _varname=="muslim_m"
replace _varname="Democratic" if _varname=="democratic_m"
replace _varname="Per-capita income" if _varname=="rgdpch1_m"
replace _varname="Government Share" if _varname=="kg_m"
replace _varname="Population" if _varname=="pop1_m"
replace _varname="Population less than 25" if _varname=="_0to25per_new_m"
replace _varname="Average Country Education" if _varname=="sch25Mean_m"
replace _varname="Women in parliament" if _varname=="womenMean_m"
replace _varname="War" if _varname=="war602000_noint_m"
replace _varname="Europe" if _varname=="europe_m"
replace _varname="Central Europe" if _varname=="c_europe_m"
replace _varname="Mediterranean" if _varname=="mediter_m"
replace _varname="Asia" if _varname=="newasia2_m"
replace _varname="Africa" if _varname=="africa_m"
replace _varname="Latin America" if _varname=="lat_amer_m"
replace _varname="Protection" if _varname=="protection_m"

xmlsave "C:\Old C Drive\F\INTIKAM2009\RESTAT\WEB_Final\RESTATWEB\Table4", doctype(excel) replace
 
